 // 随机16进制颜色
 function randomColor(){
    var str = '#'
    for(var i = 0 ; i < 6;i++){
    var num = parseInt(Math.random() * 17).toString(16)
        if(num === '10'){
            num = parseInt(Math.random() * 10)
            str += num
        }else{
            str += num
        }
    }
    return str
}

// 当前时间
function timer(){
    var date = new Date()
    var years = date.getFullYear()
    var month = date.getMonth()
    var days = date.getDate()
    var hours = date.getHours()
    var min = date.getMinutes()
    var sec = date.getSeconds()
    hours =  hours < 10 ? '0' + hours : hours
    min =  min < 10 ? '0' + min : min
    sec =  sec < 10 ? '0' + sec : sec
    return ' '+ years + '/' + month + '/' + days + ' ' + hours + ':' + min + ':' + sec
}

// 时间差
function chatimes(date1,date2){
    var time1 = date1.getTime()
    var time2 = date2.getTime()
    var chatime = time2 - time1
    chatime /= 1000
    var sec = parseInt(chatime % 60)
    var min = parseInt((chatime  / 60) % 60)
    var hours = parseInt((chatime / 3600)% 24)
    var days = parseInt(chatime / 3600 / 24)
    console.log(days)
    return  ' ' + days + ' 天 ' + hours + ' 小时 ' + min + ' 分 ' + sec + ' 秒 '
}


// 字符串转化为对象
function strToObj(_str){
    var arr =  _str.split('&')
    var obj = {}
    for(var i = 0; i < arr.length; i++){
        var nweArr = arr[i].split('=')
        obj[nweArr[0]] = nweArr[1]
    }
     return obj
}

// 对象转化为字符串
function objToStr(obj){
    str = ''
    for(var key in obj){
        str += key + obj[key]
    }
    return str
}
